package com.lagou.homework.studentmanagerpro;

import java.io.Serializable;

public class Student implements Serializable {
    private int id;
    private String name;
    private int age;
    private String gender;

    public Student() {

    }

    public Student(int id, String name, int age, String gender) throws IdException, AgeException {
        setId(id);
        setName(name);
        setAge(age);
        setGender(gender);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) throws IdException {
        if (id > 0) {
            this.id = id;
        } else {
            throw new IdException("ID输入值不合理！");
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age > 0 && age < 150) {
            this.age = age;
        } else {
            throw new AgeException("年龄输入不合理！");
        }
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }
}
